<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客详情页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_detail.css">

    <!--引入jQuery-->
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

    <!-- 引入 editor.md 的依赖 -->
    <link rel="stylesheet" href="editor.md/css/editormd.min.css">
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
    <script src="editor.md/editormd.js"></script>

</head>
<body>
    <div class="nav">
        <img src="image/blog3.JPG">
        <div class="title">我的博客系统</div>
        <!-- 只是一个空白将后面的连接挤过去 -->
        <div class="space"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="logout">注销</a>
    </div>

    <!-- 页面的主体部分 -->
    <div class="container">
        <!-- 左侧信息 -->
        <div class="container-left">
            <div class="card">
                <img src="image/blog2.JPG" alt="">
                <h3></h3>
                <a href="https://www.github.com">github 地址</a>

                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>2</span>
                    <span>1</span>
                </div>
            </div>
        </div>
        <!-- 右侧信息 -->
        <div class="container-right">
            <h3></h3>
            <div class="date"></div>
            <div id="content">
                
            </div>
        </div>
    </div>

    <script src="js/app.js"></script>
    <script>
        function getBlog(){
            $.ajax({
                type: 'get',
                url: 'blog' + location.search,
                success: function(body){
                    console.dir(body)
                    let h3 = document.querySelector('.container-right h3');
                    h3.innerHTML = body.title;
                    let dateDiv = document.querySelector('.container-right .date');
                    dateDiv.innerHTML = body.postTime;
                    // let content = document.querySelector(".content");
                    // content.innerHTML = body.content;
                    // 设置正文，正文内容应该是 markdown 格式的数据
                    // 此处要显示的应该是渲染过的 markdown 内容，而不是 markdown 的原始字符串
                    editormd.markdownToHTML('content', {markdown: body.content});
                } 
            });
        }

        getBlog();
        getLoginStatus();

        function getAuthor(){
            $.ajax({
                type: 'get',
                url:'user' + location.search,
                success: function(body){
                    if (body.userId == 0){
                        alert("当前未找到作者信息");
                        return;
                    }
                    let h3 = document.querySelector('.card h3');
                    // if (body.username == 'yutong'){
                    //     h3.innerHTML = '雨桐';
                    // }else{
                    //     h3.innerHTML = '云枫';
                    // }
                    h3.innerHTML = body.username;
                    if (body.username == 'Expire'){
                        let img = document.querySelector('.card img');
                        img.src = 'image/blog22.JPG';
                    }
                }
            });
        }
        getAuthor();
    </script>
</body>
</html>